package com.atguigu.tingshu.album.api;

import com.atguigu.tingshu.album.service.BaseCategoryService;
import com.atguigu.tingshu.common.result.Result;
import com.atguigu.tingshu.model.album.BaseAttribute;
import com.atguigu.tingshu.model.album.BaseCategory3;
import com.atguigu.tingshu.vo.category.CategoryVo;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;


@Tag(name = "分类管理")
@RestController
@RequestMapping(value="/api/album/category")
@SuppressWarnings({"unchecked", "rawtypes"})
public class BaseCategoryApiController {
    //http://localhost:8500/api/album/category/getBaseCategoryList
	@Autowired
	private BaseCategoryService baseCategoryService;
	@GetMapping("/getBaseCategoryList")
	@Operation(summary = "获取三级分类")
	public Result getBaseCategoryList(){
		List<CategoryVo> categoryVoList =baseCategoryService.getBaseCategoryList();
		return Result.ok(categoryVoList);
	}
	//Request URL: http://localhost:8500/api/album/category/findAttribute/2
	@GetMapping("/findAttribute/{category1Id}")
	@Operation(summary = "根据分类id获取分类属性")
	public Result findAttribute(@PathVariable(value = "category1Id") Long c1Id){
		List<BaseAttribute> baseAttributes = baseCategoryService.findAttributeAndValue(c1Id);
		return Result.ok(baseAttributes);
	}
	//Request URL: http://localhost:8500/api/album/category/findTopBaseCategory3/1
	@GetMapping("/findTopBaseCategory3/{category1Id}")
	@Operation(summary = "根据一级分类id获取7个三级分类")
	public Result findTopBaseCategory3(@PathVariable("category1Id") Long category1Id){
		List<BaseCategory3> baseCategory3List =baseCategoryService.findTopBaseCategory3(category1Id);
		return Result.ok(baseCategory3List);
	}
	//Request URL: http://localhost:8500/api/album/category/getBaseCategoryList/1
	@GetMapping("/getBaseCategoryList/{category1Id}")
	@Operation(summary = "根据一级分类id获取所有二级分类以及三级分类id")
	public Result getBaseCategoryListByCategory1Id(@PathVariable(value = "category1Id") Long category1Id){
		CategoryVo categoryVo = baseCategoryService.getBaseCategoryListByCategory1Id(category1Id);
		return Result.ok(categoryVo);
	}


}

